export function isNumber(val: unknown): val is number {
  return typeof val == "number";
}

export function isString(val: unknown): val is string {
  return typeof val == "string" || val instanceof String;
}

export function randStr(): string {
  return Math.random().toString(36).slice(-8);
}

export type OSType = "Windows" | "MacOS" | "Linux" | "Other";
export function getOs(): OSType {
  if (navigator.userAgent.indexOf("Win") != -1) {
    return "Windows";
  } else if (navigator.userAgent.indexOf("Mac") != -1) {
    return "MacOS";
  } else if (navigator.userAgent.indexOf("Linux") != -1) {
    return "Linux";
  }
  return "Other";
}

export function isMobile(): boolean {
  return /Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(
    navigator.userAgent,
  );
}

export function toUrlParams(params: Record<string, any>) {
  return new URLSearchParams(params).toString();
}
